﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace FFmpegVideoClip.Lib.UtilityControlsTools
{
    [ValueConversion(typeof(double[]), typeof(string))]
    internal class ProgressBarValueToString : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length < 2)
                return $"{parameter.ToString()} %0";
            double result=0;
            try { result = (values[0] is double Value ? Value : 0) / (values[1] is double MaxValue ? MaxValue : 0) * 100; }
            catch { result = 0; }
            return $"{parameter.ToString()} %{Math.Round(result, 2, MidpointRounding.AwayFromZero)}";
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
